<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002 Fr&eacute;d&eacute;ric Descamps
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

if ($_POST['id']) $id = $_POST['id'];
else $id	= $_GET['id'];
$sw		= $_POST['sw']; 
$pwd_actuel	= $_GET['pwd_actuel'];
$pwd_adm	= $_GET['pwd_adm'];
$pwd_adm2	= $_GET['pwd_adm2'];
if(!$id)
{
        $requete = "select * from admin";
        if(!($resultat = biblio_db_query($requete)))
        { print "PROBLEME : " .biblio_db_error(); }
        else 
        {
                echo "<CENTER><H3>";
		echo _("Modifier un administrateur");
		echo "</H3>";
                echo "<TABLE><TR><th>Administrateur</th><th>Action</th>";
        
                while ($row = biblio_db_fetch_array($resultat)) 
	        {      
                        $admin_id = $row['id'];           
                        $admin_nom =  $row['login'];                                
                        echo "<TR><TD>$admin_nom</TD><TD><A href=\"admin.php?action=mod&type=admin&id=$admin_id\"><IMG SRC=\"images/wh_r_arr.gif\" ALT=\"";
			echo _("changer");
			echo "\" border=0 align=right></A></TD>";            
                }
                echo "</TABLE></CENTER>";
        }
}
else
{
    if ($sw!=1)
    {
        ?>
        <CENTER><H3>
	<?php echo _("Modifier le mot de passe d'un administrateur"); ?>
	</H3>
        <FORM action=admin.php METHOD=POST>
        <TABLE BORDER=0>
        <TR>
        <TD>
	<?php echo _("Mot de passe actuel"); ?>
	:</TD><TD><INPUT TYPE="password" NAME="pwd_actu" size = 10></TD>
        <TR>
        <TD>
	<?php echo _("Nouveau Mot de passe"); ?>
	:</TD><TD><INPUT TYPE="password" NAME="pwd_adm" size = 10></TD>
        <TR>
        <TD>
	<?php echo _("Nouveau Mot de passe"); ?>
	(x2):</TD><TD><INPUT TYPE="password" NAME="pwd_adm2" size = 10></TD>
        </TABLE><BR>
        <INPUT TYPE="hidden" NAME="user" value="<?php echo $user; ?>">
        <INPUT TYPE="hidden" NAME="action" value="<?php echo $action; ?>">
        <INPUT TYPE="hidden" NAME="type" value="<?php echo $type; ?>">
        <INPUT TYPE="hidden" NAME="sw" value="1">
        <INPUT TYPE="hidden" NAME="id" value="<?php echo $id; ?>">        
        <input type="Submit" value="
	<?php echo _("Enregistrer"); ?>
	">
        </FORM>
        </CENTER>
        <?php
    }   
    else
    {
    
      $requete = "SELECT * FROM admin WHERE id=$id";
      $resultat = biblio_db_query($requete);
      while ($row=biblio_db_fetch_array( $resultat ))
      {
        if(md5($pwd_actu) == $row['pwd'])
        {
         echo "<CENTER><BR>";
	 echo _("Le mot de passe actuel n'est pas valide, recommencez!");
	 echo "<BR><BR>";
         echo "<A href=\"admin.php?action=mod&type=admin&id=$admin_id\">";
	 echo _("retour");
	 echo "</A></CENTER>";
         exit;
        }
      }
      if($pwd_adm != $pwd_adm2)
      {
        echo "<CENTER><BR>";
	echo _("Les mots de passe entr&eacute;s ne sont pas identiques, recommencez!");
	echo "<BR><BR>";
        echo "<A href=\"admin.php?action=mod&type=admin&id=$admin_id\">";
	echo _("retour");
	echo "</A></CENTER>";
        exit;
      }
      $requete = "update admin set pwd=md5('$pwd_adm') where id=$id";
      if(!($resultat = biblio_db_query($requete)))
      { echo "PROBLEME : " .biblio_db_error(); exit;}  
      put_log(3,$requete,$user);
      echo "<CENTER><BR>";
      echo _("Le mot de passe de l'administrateur a &eacute;t&eacute; modifi&eacute;.");
      echo "<br>";
    } 
}
?>
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
